﻿using System.Data.Entity;
using xTeam.Glgcx.CommonUtilities;

namespace xTeam.Glgcx.DataAccess
{
    public class GlgcxDataBase : DbContext
    {
        public DbSet<EClassify> Classify { get; set; }
        public DbSet<ENews> Archive { get; set; }
        public DbSet<EAlbum> Album { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public GlgcxDataBase()
        {

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<EClassify>()
                .HasKey(i => i.ClassifyId)
                .ToTable("Classify");

            modelBuilder.Entity<EClassify>().Ignore(i => i.ChildList);
            modelBuilder.Entity<EClassify>().Ignore(i => i.Descendant);
            modelBuilder.Entity<EClassify>().Ignore(i => i.Parent);

            modelBuilder.Entity<ENews>()
                .HasKey(i => i.NewsId)
                .ToTable("News");


            modelBuilder.Entity<ENews>().Property(i => i.Contents).IsMaxLength();



            modelBuilder.Entity<EAlbum>()
             .HasKey(i => i.ImageId)
             .ToTable("News_Image");


        }

    }

    public class GlgcxDataBaseInitial : IDatabaseInitializer<GlgcxDataBase>
    {


        public void InitializeDatabase(GlgcxDataBase context)
        {
            //context.Set<ENews>().Create();
        }
    }

}
